<template>
	<transition name="confirm-fade">
		<div class="confirm" v-show="showFlag" @click.stop>
			<div class="confirm-wrapper">
				<div class="confirm-content">
					<p class="text">{{text}}</p>
					<div class="operate">
						<div class="operate-btn operate-btn-cancel" @click="cancel">{{cancelBtnText}}</div>
						<div class="operate-btn operate-btn-confirm" @click="confirm">{{confirmBtnText}}</div>
					</div>
				</div>
			</div>
		</div>
	</transition>
</template>

<script>
export default {
	props: {
		text: {
			type: String,
			default: ''
		},
		confirmBtnText: {
			type: String,
			default: '确定'
		},
		cancelBtnText: {
			type: String,
			default: '取消'
		}
	},
	data() {
		return {
			showFlag: false
		}
	},
	methods: {
		show() {
			this.showFlag = true
		},
		hide() {
			this.showFlag = false
		},
		cancel() {
			this.hide()
			this.$emit('cancel')
		},
		confirm() {
			this.hide()
			this.$emit('confirm')
		}
	}
}
</script>

<style lang="scss" scoped>
@import "@/assets/css/mixin.scss";
.confirm  {
	width: 100%;
	height: 100%;
	background: rgba(0, 0, 0, 0.4);
	position: fixed;
	left: 0;
	top: 0;
	z-index: 998;
}
.confirm, .confirm-fade-enter-active {
  animation: confirm-fadein 0.3s;
}
.confirm-wrapper {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 999;
}

.confirm-wrapper .confirm-content {
  width: 270px;
  border-radius: 13px;
  background: #333;
	animation: confirm-zoom 0.3s;
}

.confirm-content .text {
  padding: 19px 15px;
  line-height: 22px;
  text-align: center;
  font-size: rem(18);
  color: rgba(255, 255, 255, 0.746);
}

.confirm-content .operate {
  display: flex;
  align-items: center;
  text-align: center;
  font-size: rem(18);
}

.operate .operate-btn {
  flex: 1;
	padding: 10px 0;
	border-top: 1px solid rgba(0, 0, 0, 0.3);;
  line-height: 22px;
  color: rgba(255, 255, 255, 0.52);;
}

.operate-btn, .operate-btn-cancel {
  border-right: 1px solid rgba(0, 0, 0, 0.3);
}
.operate-btn-cancel:active,
.operate-btn-confirm:active {
	box-shadow: 0 0 2px #ffccff;
}
/* 弹入动画 */
@keyframes confirm-fadein {
  0% {
    opacity: 0;
  }

  100% {
    opacity: 1;
  }
}
/* 弹出动画 */
@keyframes confirm-zoom {
  0% {
    transform: scale(0);
  }

  50% {
    transform: scale(1.1);
  }

  100% {
    transform: scale(1);
  }
}
</style>